package com.atguigu.gilimall.thirdpart.controller;

import com.atguigu.common.utils.R;
import com.atguigu.gilimall.thirdpart.service.SmsService;
import com.atguigu.gilimall.thirdpart.utils.SmsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/** 短信验证码的服务
 * @Author ShiJieLin
 * @Date 2022/4/20 21:45
 * @Version 1.0
 */
@Controller
@Slf4j
public class SmsController {

    @Resource
    private SmsService smsService;

    @GetMapping("/send/sms")
    @ResponseBody
    public R sendMsm(@RequestParam(value = "phone") String phone) {

        String code = SmsUtil.getSixBitRandom();
        Map<String,Object> param = new HashMap<>();
        param.put("code",code);
        log.info("远程调用成功code:{}" + code);
        Boolean isSend = smsService.send(phone, param);

        return R.ok().put("code", code).put("isSend", isSend);
    }


}
